package com.webex.ta.hydra.core.macro;

import com.webex.ta.hydra.core.Command;

import java.util.Map;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-15
 * Time: 8:49:38
 */
public class MacroParameterReplacer {
    public static void replaceParameter(Command cmd, Map<String, String> entries) {
        for (int i = 0; i< cmd.getParameters().size(); i++) {
            String param = cmd.getParameters().get(i);
            for (Map.Entry<String, String> entry : entries.entrySet()) {
                if (param != null) {
                    param = param.replace("#" + entry.getKey(), entry.getValue());
                }
            }
            cmd.setParameter(i, param);
        }
        if (cmd.hasChild()) {
            for (int i = 0; i < cmd.getChildCount(); i++) {
                replaceParameter(cmd.getChildAt(i), entries);
            }
        }
    }
}
